package com.congee02.dbservlet.framework.orm;


import com.congee02.dbservlet.framework.orm.annotation.TableColumn;

import java.lang.reflect.Field;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 将数据库的列转化为对象的字段
 */
final class Column2FieldUtils {

    private Column2FieldUtils() {
    }

    static <T> ConcurrentMap<String, Field> columnFieldMap(Class<T> clazz) {
        Field[] fields = clazz.getDeclaredFields();
        ConcurrentMap<String, Field> result = new ConcurrentHashMap<>(fields.length);
        for (Field field : fields) {
            TableColumn tableColumnAnnotation = field.getAnnotation(TableColumn.class);
            if (tableColumnAnnotation != null) {
                result.put(tableColumnAnnotation.columnName(), field);
            }
        }
        return result;
    }

}
